/*
* Nom de classe : GUIManager
*
* Description   : Gestion de l'interface graphique
*
* Version       : 0.0
*
* Date          : 31/01/2014
*
* Update     	: Julian
*/
package org.exia.minisig.swing.controller;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JFrame;
import javax.swing.Timer;

import org.exia.minisig.model.object.Place;
import org.exia.minisig.swing.view.home.HomeFram;
import org.exia.minisig.swing.view.navigation.NavigationFram;

/**
* GUIManager - Gestionnaire de l'affichage
* -Fournis l'instance de la JFram principal
* -Instancie les composant de l'affichage
* 
* @version0.0
* @date 31/01/2013
*/
public class GUIManager implements ActionListener{
	//var
	private JFrame currentFram;
	private javax.swing.Timer refreshTimer;
	//GET & SET	
	public JFrame getCurrentFram() {
		return currentFram;
	}
	public void setCurrentFram(JFrame currentFram) {
		this.currentFram = currentFram;
	}
	//CONSTRUCTOR
	private GUIManager() {
		initializeVar();
	}
	private void initializeVar(){
		this.refreshTimer = new Timer(1, this);
		this.refreshTimer.start();
	}
	//SINGLETON
	public static GUIManager getInstance() {
        return GUIManagerHolder.INSTANCE;
    }
    private static class GUIManagerHolder {
        private static final GUIManager INSTANCE = new GUIManager();
    }
	//METHODE
	private void jframParameter(){
		this.currentFram.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		//this.currentFram.setLocationRelativeTo(null); 
		this.currentFram.pack();
		this.currentFram.setVisible(true); 
	}
	public void runHome(){		
		if (currentFram != null){
			this.currentFram.dispose();
		}
		this.currentFram = new HomeFram();
		jframParameter();
	}
	public void runNavigation(Place mapToLoad){		
		this.currentFram.dispose();
		this.currentFram = new NavigationFram(mapToLoad);
		jframParameter();
		
	}

	//OVERRIDE
	@Override
	public void actionPerformed(ActionEvent arg0) {
		if (currentFram != null){
			this.currentFram.repaint();
		}
	}
	
}
